home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / esc.jar / com / extensibility / exv / MultiModule.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-06-30  |  5.4 KB  |  265 lines

  1. package com.extensibility.exv;
  2.  
  3. import com.extensibility.xml.XMLWriter;
  4. import java.io.File;
  5. import java.io.FileOutputStream;
  6. import java.io.IOException;
  7. import java.io.Serializable;
  8. import java.io.Writer;
  9. import java.util.Hashtable;
  10. import java.util.Random;
  11. import java.util.Vector;
  12.  
  13. public abstract class MultiModule implements Serializable {
  14.    public static final int FLAVOR_STRARRAY = 0;
  15.    public static final int FLAVOR_ZIP = 1;
  16.    int flavor;
  17.    boolean persistent = false;
  18.    private static String ROOT_PATH = "d:\\tmp";
  19.    File localDir;
  20.    protected Hashtable validValues = new Hashtable();
  21.    protected Hashtable wfValues = new Hashtable();
  22.    protected Hashtable errors = new Hashtable();
  23.    protected boolean[] map;
  24.    protected String[] fileNameMap;
  25.  
  26.    public MultiModule(int var1, boolean var2) {
  27.       this.flavor = var1;
  28.       this.localDir = new File(ROOT_PATH, this.getRandomPath());
  29.       this.persistent = true;
  30.    }
  31.  
  32.    public Hashtable getValidValues() {
  33.       return (Hashtable)this.validValues.clone();
  34.    }
  35.  
  36.    public Hashtable getWfValues() {
  37.       return (Hashtable)this.wfValues.clone();
  38.    }
  39.  
  40.    public boolean getParseable(int var1) throws ArrayIndexOutOfBoundsException {
  41.       return this.map[var1];
  42.    }
  43.  
  44.    public boolean getParseable(String var1) throws ArrayIndexOutOfBoundsException {
  45.       return this.getParseable(this.getIndexOfSchema(var1));
  46.    }
  47.  
  48.    public void setParseable(int var1, boolean var2) throws ArrayIndexOutOfBoundsException {
  49.       this.map[var1] = var2;
  50.    }
  51.  
  52.    public void setParseable(String var1, boolean var2) throws ArrayIndexOutOfBoundsException {
  53.       this.setParseable(this.getIndexOfSchema(var1), var2);
  54.    }
  55.  
  56.    public int getNotParseableCount() {
  57.       int var1 = 0;
  58.  
  59.       for(int var2 = 0; var2 < this.map.length; ++var2) {
  60.          if (!this.map[var2]) {
  61.             ++var1;
  62.          }
  63.       }
  64.  
  65.       return var1;
  66.    }
  67.  
  68.    public boolean[] getMap() {
  69.       return this.map;
  70.    }
  71.  
  72.    public void setMap(boolean[] var1) throws SchemaException {
  73.       if (var1 == null) {
  74.          throw new SchemaException("Invalid map");
  75.       } else {
  76.          this.map = var1;
  77.       }
  78.    }
  79.  
  80.    public void setMap(int var1, boolean var2) throws SchemaException {
  81.       if (var1 < 0) {
  82.          throw new SchemaException("Invalid map size");
  83.       } else {
  84.          this.map = new boolean[var1];
  85.  
  86.          for(int var3 = 0; var3 < var1; ++var3) {
  87.             this.map[var3] = var2;
  88.          }
  89.  
  90.       }
  91.    }
  92.  
  93.    public boolean isEmpty() {
  94.       return this.fileNameMap.length == 0;
  95.    }
  96.  
  97.    public int size() {
  98.       return this.fileNameMap.length;
  99.    }
  100.  
  101.    public void clear() {
  102.       if (this.persistent) {
  103.          System.gc();
  104.          this.clearDir(this.localDir);
  105.          this.localDir.delete();
  106.       }
  107.  
  108.    }
  109.  
  110.    void saveToFile(String[] var1, String[] var2) throws IOException {
  111.       this.localDir.mkdir();
  112.  
  113.       for(int var3 = 0; var3 < var1.length; ++var3) {
  114.          XMLWriter var4 = new XMLWriter(new FileOutputStream(new File(this.localDir, var1[var3])));
  115.          ((Writer)var4).write(var2[var3]);
  116.          var4.flush();
  117.          var4.close();
  118.       }
  119.  
  120.    }
  121.  
  122.    Vector retDeclErrors(String var1) throws SchemaException {
  123.       if (!this.errors.containsKey(var1)) {
  124.          throw new SchemaException("The schema was not validated.");
  125.       } else {
  126.          return (Vector)((SchemaAllErrors)this.errors.get(var1)).getDeclErrors().clone();
  127.       }
  128.    }
  129.  
  130.    int retDeclErrorsCount(String var1) throws SchemaException {
  131.       if (!this.errors.containsKey(var1)) {
  132.          throw new SchemaException("The schema was not validated.");
  133.       } else {
  134.          return ((SchemaAllErrors)this.errors.get(var1)).getDeclErrors().size();
  135.       }
  136.    }
  137.  
  138.    Vector retParseErrors(String var1) throws SchemaException {
  139.       if (!this.errors.containsKey(var1)) {
  140.          throw new SchemaException("The schema was not validated.");
  141.       } else {
  142.          return (Vector)((SchemaAllErrors)this.errors.get(var1)).getParseErrors().clone();
  143.       }
  144.    }
  145.  
  146.    int retParseErrorsCount(String var1) throws SchemaException {
  147.       if (!this.errors.containsKey(var1)) {
  148.          throw new SchemaException("The schema was not validated.");
  149.       } else {
  150.          return ((SchemaAllErrors)this.errors.get(var1)).getParseErrors().size();
  151.       }
  152.    }
  153.  
  154.    Vector retDeclErrorsDesc(String var1) throws SchemaException {
  155.       if (!this.errors.containsKey(var1)) {
  156.          throw new SchemaException("The schema was not validated.");
  157.       } else {
  158.          return (Vector)((SchemaAllErrors)this.errors.get(var1)).getDeclErrorsDesc().clone();
  159.       }
  160.    }
  161.  
  162.    Vector retParseErrorsDesc(String var1) throws SchemaException {
  163.       if (!this.errors.containsKey(var1)) {
  164.          throw new SchemaException("The schema was not validated.");
  165.       } else {
  166.          return (Vector)((SchemaAllErrors)this.errors.get(var1)).getParseErrorsDesc().clone();
  167.       }
  168.    }
  169.  
  170.    String getPath() {
  171.       return ROOT_PATH;
  172.    }
  173.  
  174.    void setPath(String var1) {
  175.       if (var1 != null) {
  176.          ROOT_PATH = var1;
  177.       }
  178.  
  179.    }
  180.  
  181.    protected void initFileNameMap(String[] var1) {
  182.       this.fileNameMap = new String[var1.length];
  183.  
  184.       for(int var2 = 0; var2 < var1.length; ++var2) {
  185.          this.fileNameMap[var2] = var1[var2];
  186.       }
  187.  
  188.    }
  189.  
  190.    protected int getIndexOfSchema(String var1) {
  191.       for(int var2 = 0; var2 < this.fileNameMap.length; ++var2) {
  192.          if (this.fileNameMap[var2].equals(var1)) {
  193.             return var2;
  194.          }
  195.       }
  196.  
  197.       return -1;
  198.    }
  199.  
  200.    private void clearDir(File var1) {
  201.       String[] var2 = var1.list();
  202.  
  203.       for(int var3 = 0; var3 < var2.length; ++var3) {
  204.          File var4 = new File(var1, var2[var3]);
  205.          if (var4.isDirectory()) {
  206.             this.clearDir(var4);
  207.          }
  208.  
  209.          var4.delete();
  210.       }
  211.  
  212.    }
  213.  
  214.    private String getRandomPath() {
  215.       Random var1 = new Random(System.currentTimeMillis());
  216.       StringBuffer var2 = new StringBuffer();
  217.  
  218.       for(int var3 = 0; var3 < 10; ++var3) {
  219.          var2.append((char)(97 + (int)(var1.nextFloat() * (float)25)));
  220.       }
  221.  
  222.       return var2.toString();
  223.    }
  224.  
  225.    abstract void changedSchema(String var1);
  226.  
  227.    public abstract int countFlavor(String var1);
  228.  
  229.    public abstract Vector getSchemas();
  230.  
  231.    public abstract SchemaWrapper getSchema(String var1) throws SchemaException;
  232.  
  233.    public abstract void validate();
  234.  
  235.    public abstract void validate(String var1) throws SchemaException;
  236.  
  237.    public abstract boolean isValid() throws SchemaException;
  238.  
  239.    public abstract boolean isValid(String var1) throws SchemaException;
  240.  
  241.    public abstract boolean isWellFormed() throws SchemaException;
  242.  
  243.    public abstract boolean isWellFormed(String var1) throws SchemaException;
  244.  
  245.    public abstract String getResults(String var1) throws SchemaException;
  246.  
  247.    public abstract Vector getValidSchemas();
  248.  
  249.    public abstract Vector getNotValidSchemas();
  250.  
  251.    public abstract Vector getWfSchemas();
  252.  
  253.    public abstract Vector getNotWfSchemas();
  254.  
  255.    public abstract Vector getNotParseable();
  256.  
  257.    public abstract Vector getDeclErrors(String var1) throws SchemaException;
  258.  
  259.    public abstract Vector getParseErrors(String var1) throws SchemaException;
  260.  
  261.    public abstract Vector getDeclErrorsDesc(String var1) throws SchemaException;
  262.  
  263.    public abstract Vector getParseErrorsDesc(String var1) throws SchemaException;
  264. }
  265.